//

// (  )
//

package com.tools.acceleratecore.logic.accelerate.temperature.impl;

import android.content.Context;
import com.tools.acceleratecore.AccelerateCoreFactory;
import com.tools.acceleratecore.logic.accelerate.temperature.intf.ITemperatureMgr;
import com.tools.acceleratecore.logic.accelerate.temperature.intf.ITemperatureMgrListener;
import com.tools.acceleratecore.xlib.XLibFactory;
import com.tools.acceleratecore.xlib.util.UtilHardware;
import com.tools.acceleratecore.xlib.xlib.impl.XObserver;
import com.tools.acceleratecore.xlib.xlib.intf.IXThreadTask;
import com.tools.acceleratecore.xlib.xlib.intf.IXThreadTaskListener;
import java.util.Iterator;

public class TemperatureMgr extends XObserver<ITemperatureMgrListener> implements ITemperatureMgr {
    private Context mContext = null;
    private boolean mInited = false;
    private double mTemperature = 0.0D;
    private double mTemperatureOptimize = 0.0D;
    private IXThreadTask mIXThreadTaskInit = null;
    private IXThreadTask mIXThreadTaskScanTemperature = null;
    private static final int VALUE_INT_TEMPERATURE_OPTIMIZE_MAX = 3;

    public TemperatureMgr() {
        this.mContext = AccelerateCoreFactory.getApplication();
        this._init();
    }

    private void _init() {
        this.mIXThreadTaskInit = (IXThreadTask)XLibFactory.getInstance().createInstance(IXThreadTask.class);
        this.mIXThreadTaskScanTemperature = (IXThreadTask)XLibFactory.getInstance().createInstance(IXThreadTask.class);
    }

    public boolean init() {
        if(this.mInited) {
            return false;
        } else {
            this.mInited = true;
            this.mIXThreadTaskInit.start(new IXThreadTaskListener() {
                public void onThreadWork() {
                }

                public void onThreadComplete() {
                    synchronized(TemperatureMgr.this.mListListener) {
                        Iterator var3 = TemperatureMgr.this.getListListener().iterator();

                        while(var3.hasNext()) {
                            ITemperatureMgrListener listener = (ITemperatureMgrListener)var3.next();
                            listener.onCpuTemperatureMgrInitComplete();
                        }

                    }
                }
            });
            return true;
        }
    }

    public void startScanTemperatureAsyn() {
        this.mIXThreadTaskScanTemperature.start(new IXThreadTaskListener() {
            public void onThreadWork() {
                TemperatureMgr.this.startScanTemperatureSyn();
            }

            public void onThreadComplete() {
                synchronized(TemperatureMgr.this.mListListener) {
                    Iterator var3 = TemperatureMgr.this.getListListener().iterator();

                    while(var3.hasNext()) {
                        ITemperatureMgrListener listener = (ITemperatureMgrListener)var3.next();
                        listener.onStartScanTemperatureAsynComplete();
                    }

                }
            }
        });
    }

    public void startScanTemperatureSyn() {
        this.scanTemperatureSyn();
    }

    private void scanTemperatureSyn() {
        double dCpuUsage = UtilHardware.getCpuUsageTotalWithoutOwnPID() * 100.0D;
        this.mTemperatureOptimize = dCpuUsage / 33.0D + 2.0D;
        this.mTemperature = UtilHardware.getBatteryTemperature(this.mContext);
    }

    public double getTemperature() {
        return this.mTemperature;
    }

    public double getOptimizeTemperature() {
        return this.mTemperatureOptimize;
    }
}
